package com.yoomiito.app.ui.anyview.order;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.yoomiito.app.ExtensionFunKt;
import com.yoomiito.app.R;
import com.yoomiito.app.interf.BaseOrderGoodsView;
import com.yoomiito.app.model.bean.AppInterfaceInfo;
import com.yoomiito.app.model.bean.GoodsDetail;
import com.yoomiito.app.model.my.MyRemainMoneyInfo;
import com.yoomiito.app.utils.AllUtils;
import com.yoomiito.app.utils.ImageLoader;
import com.yoomiito.app.utils.SpannableUtils;
import com.yoomiito.app.widget.NumControlView;
import com.yoomiito.app.widget.OnNumberChangeListener;

/**
 * 确认订单------商品信息 数量 优米抵扣
 */
public class GiftOrderGoodsView extends BaseOrderGoodsView {

    public MyRemainMoneyInfo mMoneyInfo;
    private String mGoodsPrice;//用于计算商品价格


    public GiftOrderGoodsView(Context context, GoodsDetail detail, AppInterfaceInfo appInterfaceInfo) {
        super(context,detail,appInterfaceInfo);
    }

    @Override
    public int getView() {
        return R.layout.view_youpin_order_goods;
    }

    @Override
    public void initView() {
        ImageView goodsIv = findViewById(R.id.item_order_goods_iv);
        TextView goodsTitle = findViewById(R.id.item_order_goods_title);
        TextView goodsTitle1 = findViewById(R.id.item_order_goods_title1);
        TextView goodsPrice = findViewById(R.id.item_order_goods_price);
        TextView tvPrice = findViewById(R.id.item_order_price);
        NumControlView numControlView = findViewById(R.id.num_control_view);
        LinearLayout llSend = findViewById(R.id.send_lin);
        LinearLayout llType = findViewById(R.id.ll_type);
        TextView tvType = findViewById(R.id.tv_type);
        FrameLayout frameLayout = findViewById(R.id.frameLayout);
        frameLayout.setVisibility(View.GONE);
        TextView tvSend = findViewById(R.id.tv_send_num);


        ImageLoader.getInstance().into(mContext,appInterfaceInfo.banner,goodsIv);
        goodsTitle.setText(mGoodsDetail.getTitle());
        goodsPrice.setText("¥" + appInterfaceInfo.salePrice);
        numControlView.setNum(appInterfaceInfo.againNum);
        numControlView.setMin(appInterfaceInfo.againNum);
        numControlView.setStep(appInterfaceInfo.againStep);
        numControlView.setMax(appInterfaceInfo.maxNum);
        goodsTitle1.setText(appInterfaceInfo.point);

        if(TextUtils.isEmpty(appInterfaceInfo.roleStr)){
            llType.setVisibility(GONE);
        }else {
            llType.setVisibility(VISIBLE);
            tvType.setText(appInterfaceInfo.roleStr);
        }
        if(appInterfaceInfo.giveStart >0){
            tvSend.setText("" + 0);
            llSend.setVisibility(VISIBLE);
        }else {
            llSend.setVisibility(GONE);
        }

        numControlView.setListener(new OnNumberChangeListener() {
            @Override
            public void numberChange(int num) {
                String price = AllUtils.priceMul_2(appInterfaceInfo.salePrice , num);
                String s = "合计¥" + price;
                tvPrice.setText("¥" + price);
                int p = s.indexOf("¥");
                spanText = SpannableUtils.getSizeAndPriceText(s, R.color.color_FF035B, p, s.length(), p, p + 1);
                if (mOnShowInfoListener!=null){
                    mOnShowInfoListener.onShow(spanText,num,0);
                }
                mGoodsTotalPrice = price;

                if(num > appInterfaceInfo.giveStart){
                    if(appInterfaceInfo.multiple!=0){
                        int num1 = num / appInterfaceInfo.multiple;
                        tvSend.setText(num1+"");
                    }
                }else {
                    tvSend.setText("" + 0);
                }

            }
        });

        String price = AllUtils.priceMul_2(appInterfaceInfo.salePrice , appInterfaceInfo.againNum);
        mGoodsTotalPrice = String.valueOf(price);
        String s = "合计¥" + price;
        tvPrice.setText("¥" + price);
        int p = s.indexOf("¥");
        spanText = SpannableUtils.getSizeAndPriceText(s, R.color.color_FF035B, p, s.length(), p, p + 1);
        if (mOnShowInfoListener!=null){
            mOnShowInfoListener.onShow(spanText,appInterfaceInfo.againNum,0);
        }
    }

    private void changeMoney() {
        mGoodsTotalPrice = mGoodsPrice;
    }

    public void setMoneyInfo(MyRemainMoneyInfo moneyInfo) {
        mMoneyInfo = moneyInfo;
    }
}
